<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="4" :md="6" :sm="24">
            <a-form-item label="医生姓名">
              <a-input placeholder="医生姓名" v-model="queryParam.doctorName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="4" :md="6">
            <a-form-item label="患者姓名">
              <a-input placeholder="患者姓名" v-model="queryParam.patientName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="4">
            <a-form-item label="挂号单状态">
              <a-select v-model="queryParam.status" placeholder="请选择挂号单状态">
                <a-select-option value="2">挂号成功</a-select-option>
                <a-select-option value="4">已取消</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
           <a-col :xl="5" :lg="5" :md="4" :sm="20">
            <a-form-item label="日期" :required="true" hasFeedback>
              <j-date placeholder="请选择日期" v-model="queryParam.visitTime" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>

              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <div class="table-operator">
      <a-button type="primary" icon="download" @click="handleExportXls('挂号')">导出</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!-- <a @click="refundRecord(record)">退款</a>
          <a-divider type="vertical" />
          <a @click="handleRecord(record)">处理</a>
          <a-divider type="vertical" />
          <a @click="handleSettle(record)">结算</a>
          <a-divider type="vertical" /> -->
          <a @click="handleEdit(record)">详情</a>
          <!-- <a-divider type="vertical" /> -->
<!--          <a-dropdown>-->
<!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item>-->
<!--                <a @click="handleDetail(record)">详情</a>-->
<!--              </a-menu-item>-->
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a>删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
<!--            </a-menu>-->
<!--          </a-dropdown>-->
        </span>

      </a-table>
    </div>

    <doctor-register-modal ref="DoctorRegisterModal"></doctor-register-modal>
    <doctor-register-record-modal ref="modalForm" @ok="modalFormOk"></doctor-register-record-modal>
    <doctor-register-record-modal ref="DoctorRegisterRecordModal"></doctor-register-record-modal>
    <doctor-register-record-settle ref="DoctorRegisterRecordSettle"></doctor-register-record-settle>
    <doctor-register-refound-audit ref="DoctorRegisterRefoundAudit"></doctor-register-refound-audit>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import DoctorRegisterRecordModal from './modules/DoctorRegisterRecordModal'
  import DoctorRegisterRecordSettle from './modules/DoctorRegisterRecordSettle'
  import  DoctorRegisterModal from './modules/DoctorRegisterModal'
  import  DoctorRegisterRefoundAudit from './modules/DoctorRegisterRefoundAudit'
  import JDate from '@/components/jeecg/JDate'
  
  export default {
    name: 'DoctorRegisterRecordList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      DoctorRegisterRecordModal,
      DoctorRegisterRecordSettle,
      DoctorRegisterModal,
      DoctorRegisterRefoundAudit,
      JDate
    },
    data () {
      return {
        description: 'doctor_register_record管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'挂号表id',
            align:"center",
            dataIndex: 'id'
          },
          {
            title:'医生',
            align:"center",
            dataIndex: 'doctorName'
          },
          {
            title:'号源',
            align:"center",
            dataIndex: 'hospitalName'
          },
          {
            title:'患者',
            align:"center",
            dataIndex: 'patientName'
          },
          {
            title:'患者电话',
            align:"center",
            dataIndex: 'patientMobile'
          },
          {
            title:'挂号金额',
            align:"center",
            dataIndex: 'price'
          },
          {
            title:'就诊号种',
            align:"center",
            dataIndex: 'type'
          },
          {
            title:'就诊日期',
            align:"center",
            dataIndex: 'visitTime'
          },
          {
            title:'就诊时间',
            align:"center",
            dataIndex: 'visitPart'
          },
          {
            title:'下单时间',
            align:"center",
            dataIndex: 'registerTime',
            customRender:function (text) {
              return !text?"":(text.length>16?text.substr(0,16):text)
            }
          },
          {
            title:'支付状态',
            align:"center",
            dataIndex: 'status',
            customRender:function (text) {
              // 挂号中：1；已支付：2；挂号成功：3；挂号失败：4
              var str = ""
              if(text == 0 || text == ''){
                str = "待支付"
              }else if(text == 1 || text == 2){
                str = "挂号成功"
              }else if(text == 3){
                str = "挂号失败"
              }else if(text == 4){
                str = "已取消"
              }else if(text == 5){
                str = "已失效"
              }
              return str
            }
          },
          {
            title:'结算状态',
            align:"center",
            dataIndex: 'settle',
            customRender:function (text) {
              // 结算状态：1 已结算；0 未结算
              var str = ""
              if(text == 1){
                str = "已结算"
              }else if(text == 0){
                str = "未结算"
              }
              return str
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/doctorRegisterRecord/doctorRegisterRecord/list",
          delete: "/doctorRegisterRecord/doctorRegisterRecord/delete",
          deleteBatch: "/doctorRegisterRecord/doctorRegisterRecord/deleteBatch",
          exportXlsUrl: "/doctorRegisterRecord/doctorRegisterRecord/exportXls",
          importExcelUrl: "doctorRegisterRecord/doctorRegisterRecord/importExcel",

        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      //退款处理
      refundRecord(record){
        this.$refs.DoctorRegisterRefoundAudit.viewShow(record );
      },
      // 挂号处理
      handleRecord(record){
        if(record.status < 1){
          this.$message.warning("患者还未支付，不可操作！")
        }else if(record.status == 2 || record.status == 3){
          this.$message.warning("已处理完成！")
        }else{
          this.$refs.DoctorRegisterRecordModal.viewShow(record);
        }
      },
      // 结算
      handleSettle(record){
        if(record.status <=1){
          this.$message.warning("患者挂号成功，不可操作！")
        }else if(record.status == 3){
          this.$message.warning("患者挂号失败，不可操作！")
        }else{
          if(record.settle == 1){
            this.$message.warning("已结算成功！")
          }else{
            this.$refs.DoctorRegisterRecordSettle.viewShow(record);
          }
        }
      },
      // 详情
      handleEdit(record){
        this.$refs.DoctorRegisterModal.viewShow(record);
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>